<%
    # get all the saved data collection for given role_id, model_name, action 
    # TODO again there is a better way of doing this, but for now this works.
    # to be improved...
    saved_data_collection = find_by_rima(role_id, model_name, type)
    
    @display_style = "display: none;"
    #AjubyLogger.logInfo "daf_id>>>>>>> : #{daf_id}"
    if(daf_id!=nil and daf_id=='4')
        @display_style = "display: block;"
    end    
%>

<div  id="collectionlist_<%=type%>_<%=model_name%>" style="<%=@display_style%>">
<p> Manage collections for "<%=type%>" action:</p>

<table>
<tr><td>All Collection</td><td>&nbsp;</td><td>Selected Collection</td></tr>
<tr>
<td> 
    <!-- allow only 13 characters  -->
    <select name="vals_collectionlist_<%=model_name%>_<%=type%>_all" MULTIPLE SIZE=10 style="width:80px">

    <%
       if(appmodule_all_records!=nil)
            for appmodule_row  in appmodule_all_records
                @value_id = appmodule_row.id
                
               if(!saved_data_collection.include?(@value_id))

                    begin
                        @display_val = appmodule_row.name
                    rescue
                        @display_val = appmodule_row.description
                    end    

                    # TODO 
                    #if(appmodule_row.respond_to?("name"))
                    #    @display_val = appmodule_row.name
                    #else if(appmodule_row.respond_to?("description"))
                    #    @display_val = appmodule_row.description
                    #end
                    
                    @display_val = trimstring(@display_val,7)
     %>    
                    <option value="<%=@value_id%>"><%=@display_val%></option>
                <%end%>
                    
            <%end%>
    <%else%>
        <option value="">NO RECORDS FOUND</option>
    <%end%>    
    </select>
</td>
<td>
<%
    @all_list_form_element = "document.data_access_matrix_form.vals_collectionlist_#{model_name}_#{type}_all"
    @selected_list_form_element = "document.data_access_matrix_form.vals_collectionlist_#{model_name}_#{type}_selected"
%>

<input type="button" name="copy_all_to_assigned"  value=" &gt; "  onclick="javascript:assignListVals(<%=@all_list_form_element%>,<%=@selected_list_form_element%> );"/><br>
<input type="button" name="copy_assigned_to_all"  value=" &lt; "  onclick="javascript:assignListVals(<%=@selected_list_form_element%>, <%=@all_list_form_element%>);"/></td>
<td> 
    <select name="vals_collectionlist_<%=model_name%>_<%=type%>_selected" MULTIPLE SIZE=10 style="width:80px">
        <%
            for collection_id in saved_data_collection
                @model = AjubyDataAuthorize.get_model_record(model_name, collection_id)
                
 
                    begin
                        @display_val = @model.name
                    rescue
                        @display_val = @model.description
                    end    
                
                
                @display_val = trimstring(@display_val,7)
        %>
            <option value="<%=collection_id%>"><%=@display_val%></option>
       <%
            end
       %>     
    </select>
    <input type="hidden" name="vals_collectionlist_<%=model_name%>_<%=type%>_selected_hidden"/>
</td>
</tr>
</table>
</div>
